<script>
	import {
		wxLogin
	} from '@/api/weixin/base.js'

	const BASE_URL = () => {
		return process.env.ENV_URL
	}
	import {
		mapState
	} from 'vuex';
	export default {
		onLaunch: function() {
			console.log('App Launch')
			this.wxLogin()
		},
		onShow: function() {
			console.log(BASE_URL())
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		computed: {
			...mapState(['token'])
		},
		methods: {
			// 微信登录
			wxLogin() {
				if (!this.token) {
					uni.login({
						provider: 'weixin',
						success: (loginRes) => {
							console.log('微信登录获取code:', loginRes)
							if (loginRes.code) {
								// 调用后端登录接口
								this.callLoginApi(loginRes.code)
							} else {
								console.error('获取微信登录code失败')
							}
						},
						fail: (error) => {
							console.error('微信登录失败:', error)
						}
					})
				}

			},

			// 调用登录API
			async callLoginApi(code) {
				try {
					const loginResult = await wxLogin({
						code: code
					})
					console.log('登录成功:', loginResult)

					// 保存登录信息
					if (loginResult.data) {
						const {
							token,
							userInfo
						} = loginResult.data;
						this.$store.dispatch('setToken', token);
						this.$store.dispatch('setUserInfo', userInfo)
					}
				} catch (error) {
					console.error('调用登录API失败:', error)
				}
			}
		}
	}
</script>

<style lang="scss">
	@import '@/uni_modules/uview-ui/index.scss';
	@import '@/uni_modules/uview-ui/theme.scss';
	/*每个页面公共css */
</style>

<!-- <style lang="scss">
	@import '@/uni_modules/uview-ui/index.scss';
	@import '@/assets/reset.scss';
	@import '@/assets/fontStyle.scss';
	@import '@/assets/orderStyle.scss';
	@import '@/assets/common.scss';
	@import '@/assets/stylesheet.css';
	@import '@/assets/popup.scss';
	@import '@/assets/formCardStyle.scss';

* {
	box-sizing: border-box;
}
.radius-type--card {
	border-radius: 10rpx;
}

.share-btn,.avatar-btn {
	position: relative;

		button {
			opacity: 0;
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 100%;
			padding: 0;
		}
	}

.footer {
	border-top: 1px solid #f1f1f1;
	background-color: #fff;
	padding: 25rpx 25rpx 55rpx;
}

	.bottomBar {
		box-sizing: border-box;
		width: 100%;
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 10;

		&:empty {
			display: none
		}
	}
</style> -->